<template>
  <div style="padding: 2% 5% 0 5%">
    <a-radio-group
      v-model:value="activeKey.line1"
      button-style="solid"
      @change="getFeed"
    >
      <a-radio-button
        v-for="tab in tabkey1"
        :key="tab.title"
        :value="tab.key"
        >{{ tab.title }}</a-radio-button
      >
    </a-radio-group>

    <a-divider />
    <a-radio-group
      v-model:value="activeKey.line2"
      button-style="solid"
      @change="getFeed"
    >
      <a-radio-button
        v-for="tab in tabkey2"
        :key="tab.title"
        :value="tab.key"
        >{{ tab.title }}</a-radio-button
      >
    </a-radio-group>

    <a-list
      :loading="loading"
      item-layout="vertical"
      :data-source="itemList.value"
    >
      

      <template #renderItem="{ item }">
        <a-list-item
          key="item.a_order"
          style="min-height: 100px; max-height: 300px"
        >
          <template #actions>
            <span :key="LikeOutlined">
              <component v-bind:is="LikeOutlined" style="margin-right: 8px" />
              {{ item.like_count }}
            </span>
            <span :key="MessageOutlined">
              <component
                v-bind:is="MessageOutlined"
                style="margin-right: 8px"
              />
              {{ item.com_count }}
            </span>
            <span :key="StarOutlined" style="margin-right: 8px">
              <component v-bind:is="StarOutlined" style="margin-right: 8px" />
              {{ item.sub_count }}
            </span>
            <span :key="'Author'" >
              <a-avatar style="margin-right: 8px"
                v-if="item.u_avatar"
                :src="'/api/avatar/' + item.u_avatar"
              />
              <a-avatar v-else style="margin-right: 8px">
                <template #icon>
                  <UserOutlined />
                </template>
              </a-avatar>
              {{item.u_name}}
            </span>
          </template>

          <a-list-item-meta>
            <template #title>
              <a :href="'/user/articledetail?a_id=' + item.a_id">{{
                item.a_title
              }}</a>
            </template>
          </a-list-item-meta>

          <div>{{ item.a_html }}</div>
          <div>
            <a-image
              height="60px"
              v-for="url in item.imglist"
              :key="url"
              :src="url"
            />
          </div>
        </a-list-item>
      </template>
    </a-list>
  </div>
</template>

<script>
import { defineComponent, ref, reactive } from "vue";
import { get, post, tip } from "@/common";
import {
  StarOutlined,
  LikeOutlined,
  MessageOutlined,
  UserOutlined,
} from "@ant-design/icons-vue";

const activeKey = ref({
  line1: "3",
  line2: "1",
});

const tabkey1 = ref([
  { key: "3", title: "三天内" },
  { key: "7", title: "一周内" },
  { key: "30", title: "一月内" },
  { key: "0", title: "全部时间" },
]);
const tabkey2 = ref([
  { key: "1", title: "综合排序" },
  { key: "2", title: "点赞排序" },
  { key: "3", title: "收藏排序" },
]);

const itemList = reactive({});
const getFeed = () => {
  get("/user/feed/gethot", activeKey.value).then((res) => {
    itemList.value = res.data;
  });
};

export default defineComponent({
  setup() {
    getFeed(activeKey.value);
    return {
      tabkey1,
      tabkey2,
      activeKey,
      StarOutlined,
      LikeOutlined,
      MessageOutlined,
      UserOutlined,
      itemList,
      getFeed,
    };
  },
});
</script>

<style>
.ant-radio-button-wrapper,
.ant-radio-button-wrapper:last-child,
.ant-radio-button-wrapper:first-child {
  line-height: 25px;
  height: 25px;
  border-radius: 10px 10px 10px 10px;
  position: static;
  border-left: 1px solid #d9d9d9;
}
.ant-radio-button-wrapper,
.ant-radio-button-wrapper:last-child {
  margin-left: 10px;
}
.ant-radio-button-wrapper:not(:first-child)::before {
  position: fixed;
}
.ant-divider-horizontal {
  margin: 12px 0;
}
</style>